window.onload = function() {
	seajs.use(['jquery-1.8.2.js', 'iscroll_module.js', 'mdialog_module.js', 'util_module.js'], function(Z, I, M, U) {
		var user = U.checkLogin();
		U.fillHead();
		U.fillTree();
		U.fillFooter();
		initPage();

		function initPage() { //初始化页面
			U.loadOpt(false);
			initEvent();

			U.ajaxget('/poverty/getByUser/' + user.info.id, {}, function(json) {
				if(json.success) {
					var povertyObjVO = json.models.povertyObjVO;
					//cardType = povertyObjVO.cardType == 1 ? '身份证' : '其它类型';
					if(povertyObjVO==null){
						return;
					}
					init_lifeRecord(povertyObjVO.intro);//生活记录
					get_town_vollige(povertyObjVO.areaPath);//村镇
					if(povertyObjVO.valiState==1){//待审核
						$(".exit_up").hide();
						$(".validate").text("审核中");
						$(".validate").show();
					}
					if(povertyObjVO.valiState==2){//审核未通过
						$(".exit_up").show();
						$(".validate").text("审核未通过");
						$(".validate").show();
						$(".exit_up").click(function() {
							location.href = "poor_people_edit.html?index=1";
						});
					}

					if(povertyObjVO.valiState==3){//审核通过
						$(".exit_up").hide();
						$(".validate").text("审核通过");
						$(".validate").show();
					}

					var images = "";
					if(U.getImg(povertyObjVO.images).length > 0) {
						images = U.getImg(povertyObjVO.images)[0];
					}
					$('.head_img img').attr('src', images);
					var sex = povertyObjVO.sex == 1 ? '女' : '男';
					$('.poor_sex').text(sex);
					$('.poor_name').text(povertyObjVO.name);
					$('.poor_phone').text(povertyObjVO.connect);
					$('.poor_cardCode').text(povertyObjVO.cardCode);
					$('.poor_age').text(povertyObjVO.age);
					$('.poor_bankCode').text(povertyObjVO.bankCode);
					$('.poor_address').text(povertyObjVO.address);
					$('.poor_reamrk').text(povertyObjVO.remark);
					//$('.villageGroup').val(povertyObjVO.villageGroup);
					if(povertyObjVO.yAmountAvg == null || povertyObjVO.yAmountAvg == undefined) {
						povertyObjVO.yAmountAvg = '未知';
					}
					if(povertyObjVO.labored==1){
						$('.poor_low').text('否');
					}else{
						$('.poor_low').text('是');
					}

					$('.poor_income').text(povertyObjVO.yearAmount);//年收入
					$('.poor_request').text(povertyObjVO.requirement);//帮扶需求
					//$('.poor_reason').text(povertyObjVO.reason);
					$('.poor_prasent').text(povertyObjVO.currentReason);//申请理由
					//$('.poor_count').text(povertyObjVO.personCount);
					var povertyObjPersonList = povertyObjVO.povertyObjPersonList;
					$('table').html('');
					$(".Member_of_family_list table").append("<tr class='family_list_title'><td>关系</td><td>姓名</td><td>年龄</td><td>性别</td><td>联系方式</td><td>是否有劳动力</td><td>备注</td></tr>");
					$(povertyObjPersonList).each(function() {
						var sex = "未填写";
						if(this.sex == 1) {
							sex = "女";
						} else if(this.sex == 2) {
							sex = "男";
						}
						var laboured="未填写";
						if(this.laboured == 0) {
							laboured = "无";
						} else if(this.laboured == 1) {
							laboured = "有";
						}
						$(".Member_of_family_list table").append("<tr><td>" + this.relation + "</td><td>" + this.name + "</td><td>" + this.age + "</td><td>" + (sex) + "</td><td>"+this.connect+"</td><td>" +(laboured)+"</td><td>"+ this.remark + "</td></tr>");

					});

				} else {
					alert(json.msg);
				}
			});
		}
		function init_lifeRecord(intro){//初始化生活记录照片和描述
			var otherImage = "";//生活记录的照片
			if(intro!=null && intro!=""){

				$(".hiddenContent").html(intro);
				otherImage=$(".hiddenContent p img").attr('src');
				var reason=$(".hiddenContent p").text();

				$(".fj img").attr("src", otherImage);
				$(".lifeRecord").text(reason);//现状原因
			}
		}
		function get_town_vollige(area){
			var areaArray = area.split(',');
			var townId=areaArray[0];
			var volligeId=areaArray[1];
			var townVollige="";
			var param = {
				curPage: 1,
				pageSize: 10,
				name: null,
				provinceId: 0,
				cityId: 0,
				reason: null,
				requirement: null
			};
			U.ajaxAsync("/poverty/list", param, function(json) {
				if(json.success) {
					var address = json.models.townList;
					$(address).each(function() {
						if(townId==this.id){
							townVollige += this.name;
							U.ajaxget("location/listByPid/" + townId, null, function(json){
								//U.request("get", "location/listByPid/", townId, false, function(json) {
								if(json.success) {
									var result = json.models.locationList;
									$(result).each(function() {
										if(volligeId==this.id){
											townVollige += this.name;
											$(".poor_town").text(townVollige);
											return false;
										}
									});
								} else {
									//M.toast(false, json.errorMsg);
								}
							});
							return false;
						}
					});
				} else {
					//M.toast(false, json.errorMsg)
				}
			});
		}

		function initEvent() {
			$(".exit_login").click(function() { //退出登录
				U.writeCookie("fp_user", "", 1);
				U.writeCookie("www-pjfp-com", "", 1);
				location.href = "index.html";
			});
		}
	});

	
	
	
}

